function [ products_init_seq ] = feasability( products )
%feasability Summary of this function goes here
%   Detailed explanation goes here

    m = size(products, 1); % number of distinct end products
    products_init_seq = products;
    products = cell2mat(products(:,1:3));
 
    for curr = 1:m

        %% termination condition
        due_indices_unseq = products(curr:m,3);
        t = due_indices_unseq < curr;
        if t
            products_init_seq = [];
            curr - 1 + t
            break;
        end
        
        %% selection
        % get earliest release indices of unsequenced products
        earliest_release_indices_unseq = products(curr:m,2);
        % find out which of them is less than or equal to the curr index
        t1 = earliest_release_indices_unseq <= curr;
        
        % find earliest due date among unsequenced products
        earliest_due_index = min(due_indices_unseq);
        % find the indices of products whose wearliest release date is <= 
        % curr and whose due index/date is the smallest/earliest  
        t2 = t1 > 0 & (due_indices_unseq == earliest_due_index);
        selected_index = find(t2, 1);
        
        if selected_index
            abs_index = curr - 1 + selected_index;
            
            % swap rows
            products_init_seq([curr, abs_index],:) = products_init_seq([abs_index, curr],:);
        else
            products_init_seq = [];
            break;
        end
        
        %% update pointer
        % this step is automatic
        
    end


end

